package spring.boot.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import spring.boot.admin.model.TProvince;
import spring.boot.admin.service.TDistrictService;
import spring.boot.admin.service.TProvinceService;

import java.util.List;

@Controller
@RequestMapping("/t/district")
public class TDistrictController {

    @Autowired
    private TDistrictService tDistrictService;

    @Autowired
    private TProvinceService tProvinceService;


    /**
     * 跳转到管理页面
     */
    @GetMapping("to/list")
    @PreAuthorize("hasRole('T_DISTRICT_LIST')")
    public String toList(Model model) {
        List<TProvince> provinceList = tProvinceService.selectList();
        model.addAttribute("provinceList", provinceList);
        return "district/list";
    }


    /**
     * 分页查询
     */
    @PostMapping("list")
    @ResponseBody
    @PreAuthorize("hasRole('T_DISTRICT_LIST')")
    public IPage list(@RequestParam(defaultValue = "1") Integer page,
                      @RequestParam(defaultValue = "10") Integer rows,
                      @RequestParam(required = false) String pcode,
                      @RequestParam(required = false) String ppcode) {
        return tDistrictService.pageList(page, rows, pcode, ppcode);
    }

}
